<template>
	<view class="goods_box">
		<u-empty v-if="list.length==0"></u-empty>
		<view class="goods_list" v-else>
			<u-radio-group @change="radioChange" v-model="value" active-color='#FF365D'>
				<view class="" v-for="item in list" :key='item.id'>
					<GoodsItem :isRadio='true' :item="item"></GoodsItem>
				</view>
			</u-radio-group>
			<u-loadmore :status="status" style="width: 100%;" />
		</view>
		<view style="padding: 30rpx;" class=" btn_box">
			<u-button type="primary" shape="circle" @click="submit">发送商品</u-button>
		</view>
	</view>
</template>

<script>
	import GoodsItem from '@/components/ZY-Goods-item/ZY-Goods-item.vue'
	import initData from '@/mixin/initData.js'
	export default {
		mixins: [initData],
		components: {
			GoodsItem
		},
		props: {},
		data() {
			return {
				value: '',
				businessId: '',
				audioName: ''
			};
		},
		mounted() {
			this.miXinInit()
		},
		onLoad(e) {
			this.businessId = e.businessId
			this.audioName = e.audioName
		},
		methods: {
			submit() {
				if (this.value) {
					const sendGoods = this.list.find(item => item.id == this.value)
					
					uni.redirectTo({
						url: `/pages/chat/chat?businessId=${this.businessId}&audioName=${this.audioName}&sendGoods=${JSON.stringify(sendGoods)}`
					})
				} else {
					uni.showToast({
						title: '请选择商品',
						icon: 'none'
					})
				}
			},
			// 请求前的参数处理
			beforeInit() {
				this.apiUrl = "appBusiness/appBusinessGoodsList";
				let params = {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					id: this.businessId,
					title: ''
				};

				this.params = {
					...params
				};
			},
			radioChange(val) {
				console.log(val)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.goods_box {
		.btn_box {
			position: fixed;
			bottom: 30rpx;
			left: 0;
			width: 100%;
			z-index: 999;
		}

		.goods_list {
			padding-left: 20rpx;
		}
	}
</style>
